package com.coderg.gmall.product.controller;

import com.coderg.gmall.common.result.Result;
import com.coderg.gmall.model.product.BaseAttrInfo;
import com.coderg.gmall.product.service.BaseAttrInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description  平台属性名称接口
 * @Author CoderG
 * @Date 2025/5/16 18:05
 **/
@RestController
@RequestMapping(value = "/attr/info")
public class BaseAttrInfoController {

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    /**
     * 查询所有数据
     * @return
     */
    @GetMapping(value = "/findAll")
    public Result findAll(){
        return Result.ok(baseAttrInfoService.findAll());
    }

    /**
     * 通过id查询
     * @param id
     * @return
     */
    @GetMapping(value = "/findById")
    public Result findById(Long id){
        return Result.ok(baseAttrInfoService.selectById(id));
    }

    /**
     * 新增
     * @param baseAttrInfo
     * @return
     */
    @PostMapping
    public Result add(@RequestBody BaseAttrInfo baseAttrInfo){
        return Result.ok(baseAttrInfoService.insert(baseAttrInfo));
    }

    /**
     * 修改
     * @param baseAttrInfo
     * @return
     */
    @PutMapping
    public Result update(@RequestBody BaseAttrInfo baseAttrInfo){
        baseAttrInfoService.update(baseAttrInfo);
        return Result.ok();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        baseAttrInfoService.delete(id);
        return Result.ok();
    }

    /**
     * 条件查询
     * @param baseAttrInfo
     * @return
     */
    @PostMapping(value = "/selectByCondition")
    public Result SelectByCondition(@RequestBody BaseAttrInfo baseAttrInfo){

        return Result.ok(baseAttrInfoService.selectByCondition(baseAttrInfo));
    }
    @GetMapping(value = "/page/{page}/{size}")
    public Result SelectByPage(
            @PathVariable("page") Integer page
            ,@PathVariable("size") Integer size){
        return Result.ok(baseAttrInfoService.selectByPage(page,size));
    }

    /**
     *  条件分页查询
     * @param page
     * @param size
     * @param baseAttrInfo
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}")
    public Result SelectByPageCondition(
            @PathVariable("page") Integer page,
            @PathVariable("size") Integer size,
            @RequestBody BaseAttrInfo baseAttrInfo){
        return Result.ok(baseAttrInfoService.selectByPage(page,size,baseAttrInfo));
    }


}
